package test;

import java.lang.reflect.Method;

import org.springframework.amqp.core.Message;
import org.springframework.util.MethodInvoker;

import com.alibaba.fastjson.JSON;
import com.nuanshui.heatedloan.task.facade.bean.JobParams;
import com.nuanshui.heatedloan.task.proxy.MessageListenerBeanFactoryBuilder;
import com.nuanshui.heatedloan.task.proxy.MetaClass;


public class JavassistTest2 {
	
	public static void main(String[] args) throws Exception {
		MethodInvoker methodInvoker  = new MethodInvoker();
		Person person = new Person();
		person.setName("guohao");
		Class clazz = Person.class;
		methodInvoker.setTargetClass(clazz);
		methodInvoker.setTargetMethod("showJobParams");
		methodInvoker.setTargetObject(person);
		MetaClass metaClass = MessageListenerBeanFactoryBuilder.build().createProxyClass("test_name");
	    Object bean = metaClass.getInstance();
	    Method method =  metaClass.getSetMethod("methodInvoker");
	    method.invoke(bean,methodInvoker);
	    
	    Method targetMethod = metaClass.getTargetMethod();
	    
	    JobParams jobParams = new JobParams();
	    jobParams.addAttribute("test","abc");
	    
	    Message message = new Message(JSON.toJSONString(jobParams).getBytes(), null);
	    
	    targetMethod.invoke(bean, message,null);
	    
	    
	    
	    
	}

}
